package ${package.Controller};

import com.dave.admin.common.result.CommonPage;
import com.dave.admin.common.result.CommonResult;
import com.dave.admin.modular.boss.controller.BaseController;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};


<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!}
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
@AllArgsConstructor
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} extends BaseController {
</#if>

    @Override
    public void setPermissionPrefix() {
        this.permissionPrefix = "${table.entityName}";
    }

    private final  ${table.serviceName} ${table.serviceName};

    /**
    * 分页查询
    * @param page 分页对象
    * @return CommonResult 响应数据
    */
    @GetMapping("/page" )
    public CommonResult Page(Page page, ${table.entityName} ${table.entityName}) {
        return CommonResult.success(CommonPage.restPage(${table.serviceName}.page(page, Wrappers.query(${table.entityName}))));
    }


    /**
    * 通过id查询
    * @return CommonResult 响应数据
    */
    @GetMapping("/{id}" )
    public CommonResult getById(@PathVariable("id" ) String id) {
        return CommonResult.success(${table.serviceName}.getById(id));
    }

    /**
    * 新增
    * @return CommonResult 响应数据
    */
    @PostMapping
    public CommonResult save(@RequestBody ${table.entityName} ${table.entityName}) {
        return CommonResult.success(${table.serviceName}.save(${table.entityName}));
    }

    /**
    * 修改
    * @return CommonResult 响应数据
    */
    @PutMapping
    public CommonResult updateById(@RequestBody ${table.entityName} ${table.entityName}) {
        return CommonResult.success(${table.serviceName}.updateById(${table.entityName}));
    }

    /**
    * 通过id删除
    * @return CommonResult 响应数据
    */
    @DeleteMapping("/{id}")
    public CommonResult removeById(@PathVariable("id" ) String id) {
        return CommonResult.success(${table.serviceName}.removeById(id));
    }

}
</#if>
